// xc_lshop/savemoney/index/detail.js
var smapidata = require('../model/smapi_data.js')
// var html2wxml = require('../../../html2wxml/html2wxml.js');
// var html2wxml = require('../../../html2wxml/html2wxml');

Page({
  mixins: [require('../../../xc/mixins/basicMixin')],
  
  /**
   * 页面的初始数据
   */
  data: {
    commissionrate:0
  },
  xcloaddata: function (options, config) {

    var that=this;
    var update = {};
    console.log("options")
    console.log(config)
    this.getconfig(config)
    if(options && options.goodsId && options.source){
      this.setData({
        source: options.source
      })
      this.getmodel(options.goodsId,options.source)
    }else{
      this.error("参数不存在",true)
    }

  },
  getconfig(config){
    if (config && config.jtklmapi && config.jtklmapi.home) {
      if(config.jtklmapi.status==1){
        var update={};
        update['strollconfig'] = config.jtklmapi.stroll
        if(config.jtklmapi.distribution && config.jtklmapi.distribution.me){
          update['commissionrate'] = config.jtklmapi.distribution.me
        }

        this.setData(update)
      }else{
        this.error("功能已关闭",true)
      }
    }else{
      this.error("省钱未配制",true)
    }
  },
  tohome(){
    wx.navigateTo({
      url: '/xc_lshop/savemoney/index/index',
    })
  },
  getmodel(goodsId,source){

    var that=this;
    var model={
      'goodsId':goodsId,
      'source':source
    }
    smapidata.getpromodel(model).then(function (ret){
      console.log("getmodel")
      console.log(ret)

      if(ret['status']=1){
        var update={
          xcmodel:ret['data']
        }
        update['probanner']=that.changeimg(ret['data']['goodsCarouselPictures'])
        // html2wxml.html2wxml('article', ret.data.goodsDetailPictures, that, 5);

        that.setData(update)
      }else{
        var message=ret['message']?ret['message']:"获取失败";
        that.error(message,false)
      }

    })
  },
  changeimg(imgs){
     var banner=[];
     for(var i in imgs){
       var item={
         status:1,
        imgurl:imgs[i]
       }
       banner.push(item)
     }

     return banner;
  },
  buynow(){
    var xcmodel=this.data.xcmodel;
    console.log(this.data.xcmodel)
    if(xcmodel.we_app_info && xcmodel.we_app_info.app_id){
      wx.navigateToMiniProgram({
        appId: xcmodel.we_app_info.app_id,
        path:  xcmodel.we_app_info.page_path,
        extraData: {},
        success(res) {
          // 打开成功
        }
      })
    }else{
      wx.showToast({
        title: '小程序链接不存在',
      })
    }
   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  
})